
import {Component} from 'react';
import InputComponent from './input'
import ShowInfoComponent from './showInfo'

class StudentComponent extends Component{

    constructor(props){
        super(props);
        this.state={
            datas:[
                {"id":1,"name":"张三","age":20},
                {"id":2,"name":"李四","age":22},
                {"id":3,"name":"王五","age":24},
            ],
            ids:4
    
        }
    }
     //操作父组件的方法
    getDataFromInput=(obj)=>{
       // console.log(obj);
      this.setState({
        datas:[...this.state.datas,{id:this.state.ids+1,...obj}],
        ids:this.ids+1
    
      })
    }

    render(){
        return (
            <div>
               <InputComponent getdata={this.getDataFromInput} />
               <hr></hr>
               <ShowInfoComponent datas={this.state.datas}/>
            </div>
        )
    }
}

export default StudentComponent
